package sites.manager.admin.login;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import sites.manager.admin.account.AccountService;
import sites.manager.common.kit.Ret;
import sites.manager.common.model.Account;

/**
 * 登录控制器
 * 
 * @author zyg
 * 2022年1月23日 上午11:36:12
 */
@Controller
public class LoginController {
	
	@Autowired
	private AccountService srv;
	
	/**
	 * 进入登录界面
	 * @return
	 */
	@RequestMapping("/login")
	public String enterLogin() {
		return "login";
	}
	
	/**
	 * 进行登录校验
	 * @return
	 */
	@RequestMapping("/doLogin")
	@ResponseBody
	public Ret doLogin(Account account, HttpServletRequest request) {
		Ret ret = srv.login(account);
		if(ret.isOk()) {
			HttpSession session = request.getSession();
			session.setAttribute("account", account);
			ret.clearData();
		}
		return ret;
	}

}
